<?php

declare(strict_types=1);

namespace App\Controller\Index;


use App\Controller\BaseController;
use App\Dao\AutoReplyDao;
use App\Request\Index\UserListRequest;
use App\Request\Index\UserSearchRequest;
use App\Services\Index\HomeService;
use Hyperf\Context\Context;
use Hyperf\Di\Annotation\Inject;

class UserController extends BaseController
{

    #[Inject]
    public HomeService $homeService;

    /**
     * Note - 客户端首页用户列表接口
     * DateTime 2024/7/19 11:06
     * User Admin
     * @param UserListRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function list(UserListRequest $request)
    {
        $user = Context::get('user');
        $params = $this->request->post();
        $request->execute($params);
        $data = $this->homeService->userList($params, $user);
        return $this->return($data);

    }


    /**
     * Note - 首页搜索接口
     * DateTime 2024/8/13 11:59
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function userSearch(UserSearchRequest $request)
    {
        $user = Context::get('user');
        $params = $this->request->post();
        $request->execute($params);
        $params['language'] = Context::get('language');
        $data = $this->homeService->userSearch($user, $params);
        return $this->return($data);

    }


    /**
     * Note - 首页礼物飘窗数据接口
     * DateTime 2024/8/13 16:35
     * User Admin
     */
    public function giftShow()
    {
        $user = Context::get('user');
        $params['end_time'] = $this->request->post('end_time', time());
        $params['language'] = Context::get('language');
        $data = $this->homeService->giftShow($user, $params);
        return $this->return($data);

    }


    /**
     * Note - 获取聊天常用语
     * DateTime 2024/8/15 10:54
     * User Admin
     */
    public function getChatCommonWords()
    {
        $userInfo = Context::get('user');
        $pageSize = $this->request->post('pageSize', 20);
        $language = Context::get('language');
        $list = AutoReplyDao::getInstance()->getData($userInfo['sex'] == 2 ? 3 : 2, $language, $pageSize);
        // \Tool::JSON(\CodeData::SUCCESS, ['result' => 1, 'msg' => $list]);
        return $this->return(formatData(['result' => 1, 'msg' => $list]));

    }


    /**
     * Note - 获取匹配头像（10秒/次，连续30秒没有就返回）
     * DateTime 2024/8/19 17:43
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function getSpeedHead()
    {
        $userInfo = Context::get('user');
        $data = $this->homeService->getSpeedHead($userInfo);
        return $this->return($data);
    }
}
